<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深入理解 Java 中的自增运算符</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .code-block {
            background: linear-gradient(135deg, #1e1e2e 0%, #2d2d44 100%);
            border-radius: 16px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
            position: relative;
            overflow: hidden;
        }
        .code-block::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 40px;
            background: rgba(255, 255, 255, 0.05);
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }
        .code-dots {
            position: absolute;
            top: 14px;
            left: 20px;
            display: flex;
            gap: 8px;
        }
        .dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
        }
        .step-number {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            width: 40px;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            color: white;
            font-weight: bold;
            box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
        }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .animate-fadeInUp {
            animation: fadeInUp 0.6s ease-out;
        }
        .highlight-line {
            background: rgba(102, 126, 234, 0.1);
            border-left: 3px solid #667eea;
            margin-left: -20px;
            padding-left: 17px;
        }
        pre code {
            font-family: 'Fira Code', 'Consolas', monospace;
            font-size: 14px;
            line-height: 1.6;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="relative overflow-hidden bg-white">
        <div class="absolute inset-0 bg-gradient-to-br from-purple-50 via-white to-blue-50"></div>
        <div class="relative max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-24">
            <div class="text-center animate-fadeInUp">
                <h1 class="text-5xl md:text-6xl font-bold mb-6">
                    <span class="gradient-text">深入理解 Java 中的</span>
                    <br>
                    <span class="text-gray-800 serif-font">自增运算符</span>
                </h1>
                <p class="text-xl text-gray-600 max-w-3xl mx-auto leading-relaxed">
                    探索 i++ 和 ++i 的微妙差异，掌握前置与后置自增运算符的执行机制，
                    避免编程中的常见陷阱
                </p>
                <div class="mt-8 flex justify-center gap-4">
                    <span class="inline-flex items-center px-4 py-2 bg-purple-100 text-purple-700 rounded-full text-sm font-medium">
                        <i class="fas fa-code mr-2"></i>Java 基础
                    </span>
                    <span class="inline-flex items-center px-4 py-2 bg-blue-100 text-blue-700 rounded-full text-sm font-medium">
                        <i class="fas fa-graduation-cap mr-2"></i>编程原理
                    </span>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <section class="py-16">
        <div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
            <!-- 代码示例展示 -->
            <div class="mb-16">
                <h2 class="text-3xl font-bold text-gray-800 mb-8 text-center">
                    <i class="fas fa-terminal text-purple-600 mr-3"></i>代码示例解析
                </h2>
                
                <!-- 示例1 -->
                <div class="mb-12 animate-fadeInUp">
                    <div class="bg-white rounded-2xl shadow-lg overflow-hidden card-hover">
                        <div class="bg-gradient-to-r from-purple-600 to-blue-600 text-white px-6 py-4">
                            <h3 class="text-xl font-semibold flex items-center">
                                <i class="fas fa-puzzle-piece mr-3"></i>示例 1：自增赋值陷阱
                            </h3>
                        </div>
                        <div class="p-6">
                            <div class="code-block p-6 pt-16 mb-6">
                                <div class="code-dots">
                                    <div class="dot bg-red-500"></div>
                                    <div class="dot bg-yellow-500"></div>
                                    <div class="dot bg-green-500"></div>
                                </div>
                                <pre class="text-gray-300 overflow-x-auto"><code>int i = 0;
i = i++;
System.out.println(i); // 输出: 0</code></pre>
                            </div>
                            <div class="bg-yellow-50 border-l-4 border-yellow-400 p-4 rounded-r-lg">
                                <p class="text-gray-700">
                                    <i class="fas fa-lightbulb text-yellow-600 mr-2"></i>
                                    <strong>关键洞察：</strong>这里 i 的值仍然是 0，因为 i++ 会先返回原值 0，然后 i 自增为 1，
                                    但赋值操作又将返回的原值 0 赋给了 i，覆盖了自增的结果。
                                </p>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 示例2 -->
                <div class="animate-fadeInUp" style="animation-delay: 0.2s;">
                    <div class="bg-white rounded-2xl shadow-lg overflow-hidden card-hover">
                        <div class="bg-gradient-to-r from-blue-600 to-purple-600 text-white px-6 py-4">
                            <h3 class="text-xl font-semibold flex items-center">
                                <i class="fas fa-code-branch mr-3"></i>示例 2：前置与后置对比
                            </h3>
                        </div>
                        <div class="p-6">
                            <div class="code-block p-6 pt-16 mb-6">
                                <div class="code-dots">
                                    <div class="dot bg-red-500"></div>
                                    <div class="dot bg-yellow-500"></div>
                                    <div class="dot bg-green-500"></div>
                                </div>
                                <pre class="text-gray-300 overflow-x-auto"><code>int i = 0;
int i2 = i++;  // i2 = 0, i = 1
int i3 = ++i;  // i = 2, i3 = 2
System.out.print(i2); // 输出: 0
System.out.print(i3); // 输出: 2</code></pre>
                            </div>
                            <div class="grid md:grid-cols-2 gap-4">
                                <div class="bg-blue-50 p-4 rounded-lg">
                                    <h4 class="font-semibold text-blue-800 mb-2">
                                        <i class="fas fa-arrow-right mr-2"></i>后置自增 (i++)
                                    </h4>
                                    <p class="text-gray-700 text-sm">先使用当前值，再执行自增操作</p>
                                </div>
                                <div class="bg-purple-50 p-4 rounded-lg">
                                    <h4 class="font-semibold text-purple-800 mb-2">
                                        <i class="fas fa-arrow-left mr-2"></i>前置自增 (++i)
                                    </h4>
                                    <p class="text-gray-700 text-sm">先执行自增操作，再使用新值</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 执行机制解析 -->
            <div class="mb-16">
                <h2 class="text-3xl font-bold text-gray-800 mb-8 text-center">
                    <i class="fas fa-cogs text-purple-600 mr-3"></i>执行机制深度解析
                </h2>
                
                <div class="bg-white rounded-2xl shadow-lg p-8">
                    <div class="mb-8">
                        <h3 class="text-2xl font-semibold text-gray-800 mb-6 text-center">i++ 的三步执行过程</h3>
                        <div class="grid md:grid-cols-3 gap-6">
                            <div class="text-center card-hover bg-gradient-to-br from-purple-50 to-white p-6 rounded-xl">
                                <div class="step-number mx-auto mb-4">1</div>
                                <h4 class="font-semibold text-lg mb-2">读取</h4>
                                <p class="text-gray-600">获取变量 i 的当前值</p>
                                <i class="fas fa-eye text-3xl text-purple-600 mt-4"></i>
                            </div>
                            <div class="text-center card-hover bg-gradient-to-br from-blue-50 to-white p-6 rounded-xl">
                                <div class="step-number mx-auto mb-4">2</div>
                                <h4 class="font-semibold text-lg mb-2">计算</h4>
                                <p class="text-gray-600">将值加 1</p>
                                <i class="fas fa-calculator text-3xl text-blue-600 mt-4"></i>
                            </div>
                            <div class="text-center card-hover bg-gradient-to-br from-green-50 to-white p-6 rounded-xl">
                                <div class="step-number mx-auto mb-4">3</div>
                                <h4 class="font-semibold text-lg mb-2">赋值</h4>
                                <p class="text-gray-600">将新值存回变量</p>
                                <i class="fas fa-save text-3xl text-green-600 mt-4"></i>
                            </div>
                        </div>
                    </div>

                    <!-- 流程图 -->
                    <div class="mt-12">
                        <h3 class="text-xl font-semibold text-gray-800 mb-6 text-center">执行流程对比</h3>
                        <div class="mermaid">
                            graph LR
                                A[开始] --> B{运算符类型}
                                B -->|i++| C[返回原值]
                                B -->|++i| D[执行自增]
                                C --> E[执行自增]
                                D --> F[返回新值]
                                E --> G[结束]
                                F --> G
                                
                                style A fill:#f9f,stroke:#333,stroke-width:2px
                                style G fill:#9f9,stroke:#333,stroke-width:2px
                                style B fill:#bbf,stroke:#333,stroke-width:2px
                                style C fill:#fbb,stroke:#333,stroke-width:2px
                                style D fill:#fbf,stroke:#333,stroke-width:2px
                        </div>
                    </div>
                </div>
            </div>

            <!-- 核心概念总结 -->
            <div class="mb-16">
                <h2 class="text-3xl font-bold text-gray-800 mb-8 text-center">
                    <i class="fas fa-book text-purple-600 mr-3"></i>核心概念总结
                </h2>
                
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-gradient-to-br from-purple-100 to-purple-50 p-6 rounded-2xl card-hover">
                        <div class="flex items-start">
                            <div class="bg-purple-600 text-white p-3 rounded-lg mr-4">
                                <i class="fas fa-forward text-xl"></i>
                            </div>
                            <div>
                                <h3 class="text-xl font-semibold text-gray-800 mb-2">后置自增 (i++